**---------------------------------------------------------------------------------
** Paper: "How do past repression and indoctrination affect redistributive preferences?"
** Authors: Lars Pelke
** Contact: lars.pelke@ipw.uni-heidelberg.de
** Journal: tba
** Replication: All tables and graphs in MANUSCRIPT

cd "insert your directory here"

***-----------------------------------------------------------*****
* Import Mulitple Imputated Datasets *

use "data\data1.dta", clear
mi import flongsep data_new, using("data\data1.dta" "data\data2.dta" "data\data3.dta" "data\data4.dta" "data\data5.dta" "data\data6.dta" "data\data7.dta" "data\data8.dta" "data\data9.dta" "data\data10.dta") ///
 id(individual_id) imputed(education_3 unemployed income_deciles sex)
sleep 5000
mi convert mlong


***-----------------------------------------------------------*****
* Data management + 

gen dataset = 1 
replace dataset = 2 if data =="EVS"
replace dataset = 3 if data =="ESS"
replace dataset = 4 if data =="ISSP"
replace dataset = 5 if data =="Latinobarometer"

tab dataset

table(cohortmatch5_15)

table cohortmatch5_15 country_name


*center variables*

sum v2x_polyarchy, meanonly
gen v2x_polyarchy_c=v2x_polyarchy-r(mean)

sum e_migdppcln, meanonly
gen e_migdppcln_c=e_migdppcln-r(mean)


sum v2x_clphy_5, meanonly
gen v2x_clphy_5_c=v2x_clphy_5-r(mean)


sum v2exl_legitideol_5, meanonly
gen v2exl_legitideol_5_c=v2exl_legitideol_5-r(mean)

drop v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5
rename (v2x_polyarchy_c e_migdppcln_c v2x_clphy_5_c v2exl_legitideol_5_c) (v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5)




* Model 4 - repression

	set more off
	mi estimate, post: xtmixed  red_pref age c.time_under_autocracy_15##c.v2x_clphy_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m4
	
	outreg2 using Table2MI.doc, replace ctitle(Model 4)
	outreg2 using Table2MI.tex, replace ctitle(Model 4)
	
* FIGURE XX.A
 	
estimates restore m4
	mimrgns ,  at(time_under_autocracy_15=(0 10 20 30 40 50 60) v2x_clphy_5=(-.627804 0 .627804)) atmeans cmdmargins	
	*cmdmargins is necessarcy to use marginsplots afterwards 
	marginsplot,	xlabel(0 (10) 60,  angle(horizontal)labsize(small))   ///
	ylabel(40(1)50 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of Time under autocracy" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy  (at c)", size(medsmall))  ///
	legend(order(4 "-2 SD"  5 "Mean" 6 "+2 SD" ) position(12) ring(0) )  ///
	title("A. Time under Autocracy by Repression (at c) on preferences for redistribution.", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4d, replace)
	
	graph save Output/Figure1MI, replace
	graph export Output/Figure1MI.pdf, replace

	
* Model 5 - ideology

	set more off
	mi estimate, post: xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m5

outreg2 using Table3.doc, replace ctitle(Model 5)
outreg2 using Table3.tex, replace ctitle(Model 5)


* FIGURE XX.B

estimates restore m5
	mimrgns ,  at(time_under_autocracy_15=(0 10 20 30 40 50 60) v2exl_legitideol_5=(-2.573788  0 3.118372)) atmeans cmdmargins	
	marginsplot,	xlabel(0 (10) 60,  angle(horizontal)labsize(small))   ///
	ylabel(40(1)50 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of Time under autocracy" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy", size(medsmall))  ///
	legend(order(4 "-Min"  5 "Mean" 6 "+2 SD" ) position(12) ring(0) )  ///
	title("A. Time under Autocracy by Indoctrination (at c) on preferences for redistribution.", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4e, replace)
	
	graph save Output/Figure2MI, replace
	graph export Output/Figure2MI.pdf, replace


	
* Model 6 - ideology + repression interaction

	set more off
	mi estimate, post: xtmixed  red_pref age c.time_under_autocracy_15##c.v2x_clphy_5##c.v2exl_legitideol_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m6

outreg2 using Table4.doc, append ctitle(Model 6)
outreg2 using Table4.tex, append ctitle(Model 6)

 estimates restore m6
	mimrgns, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5=(-2.573788  0 3.118372) v2x_clphy_5=(-.627804 0 .627804)) atmeans cmdmargins
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(40(1)50 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of indoctrination (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy", size(medsmall))  ///
	legend(order( 4 "-2 SD"  5 "Mean" 6 "+2 SD" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/Figure3MI, replace
	graph export Output/Figure3MI.pdf, replace
	
	
***-----------------------------------------------------------*****
* Robustness Test: Democracy at T * Repression * Exposure to Autocracy+ 

	set more off
	mi estimate, post: xtmixed  red_pref age c.time_under_autocracy_15##c.v2x_clphy_5##c.v2x_polyarchy ///
	e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m1C

outreg2 using Table_hypothesis2C.doc, append ctitle(Model 1)
outreg2 using Table_hypothesis2C.tex, append ctitle(Model 1)

 estimates restore m1C
	mimrgns, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2x_clphy_5=(-.627804 0 .627804) v2x_polyarchy=(0.1 0.5 0.9)) atmeans cmdmargins
	marginsplot, by(v2x_polyarchy) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(40(1)50 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of democracy (at t)" "on redistribution preferences", size(medsmall)) ///
	xtitle("time under autocracy", size(medsmall))  ///
	legend(order( 4 "-2 SD"  5 "Mean" 6 "+2 SD" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/Figure7Robust, replace
	graph export Output/Figure7Robust.pdf, replace
